﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//Tests admin programs
public partial class Admin_Asp_TestAdmin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /*if (!LoginHandler.IsLoggedIn(Session))
        {
            Response.Redirect(Paths.admin_index);
        }*/
        
        RunTests();
    }

    private void RunTests()
    {
        //TODO: Alter The paths so it leads to some testing folder instead of the "real" thing
        ProgramHandlerTester f_programHandlerTester = new ProgramHandlerTester(Session);

        StartTest(x_programHandlerTester);

        f_programHandlerTester.m_result = f_programHandlerTester.RunTest();

        UpdateStatus(x_programHandlerTester, f_programHandlerTester);
    }

    private void StartTest(Label a_statusLabel)
    {
        a_statusLabel.Text = "Started Test...";
    }

    private void UpdateStatus(Label a_statusLabel,TestClass a_testClass)
    {
        if (a_testClass.m_result)
        {
            a_statusLabel.Text = "Works";
            //CSS class changes depending on result
        }
        else
        {
            a_statusLabel.Text = (a_testClass.GetError() != "") ? a_testClass.GetError() : "Failed";
        }
    }
}